package com.ai.scheduled;

import com.ai.common.CommonResponse;
import com.ai.common.constant.OpcConstant;
import com.ai.entity.made.ModbusNodeInfo;
import com.ai.entity.made.ModbusServerInfo;
import com.ai.entity.made.OpcServerInfo;
import com.ai.modbus.ModbusFactoryProvide;
import com.ai.modbus.ModbusProvide;
import com.ai.modbus.ModbusReadRunnable;
import com.ai.opc.OpcThreadPoolExecutor;
import com.ai.service.made.IModbusNodeInfoService;
import com.ai.service.made.IModbusServerInfoService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.ImmutableList;
import com.serotonin.modbus4j.ModbusMaster;
import com.serotonin.modbus4j.code.DataType;
import com.serotonin.modbus4j.exception.ErrorResponseException;
import com.serotonin.modbus4j.exception.ModbusInitException;
import com.serotonin.modbus4j.exception.ModbusTransportException;
import com.serotonin.modbus4j.ip.IpParameters;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.milo.opcua.sdk.client.api.UaClient;
import org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaSubscription;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

import static net.sf.jsqlparser.parser.feature.Feature.offset;

/**
 * modbus节点定时任务
 * 定期轮询读取
 * @Author jiaok
 * @Date 2024-11-27 10:50
 */
@Component
@Slf4j
public class ModbusDetectJob {

    @Resource
    private IModbusServerInfoService iModbusServerInfoService;

    @Resource
    private IModbusNodeInfoService iModbusNodeInfoService;

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Scheduled(cron = "0 */3 * * * ?")
    public void doTask(){
        log.info("========================    开始定时读取Modbus节点内容    ========================");
        iModbusServerInfoService.readModbusServerNodeInfo();

    }
}
